/* GUI CONVERTED from mfivtr.i (converter v1.76) Mon Jun 30 07:59:37 2003 */
/* mfivtr.i - INCLUDE FILE TO CREATE TRANSACTION FOR SHIPMENT                */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.46.1.1 $                                        */

/* REVISION: 1.0      LAST MODIFIED: 08/31/86   BY: pml *17  *               */
/* REVISION: 6.0      LAST MODIFIED: 04/03/90   BY: WUG *D015*               */
/* REVISION: 6.0      LAST MODIFIED: 04/05/90   BY: ftb *D002*               */
/* REVISION: 6.0      LAST MODIFIED: 04/16/90   BY: WUG *D002*               */
/* REVISION: 6.0      LAST MODIFIED: 04/30/90   BY: MLB *D021*               */
/* REVISION: 6.0      LAST MODIFIED: 10/26/90   BY: pml *D143*               */
/* REVISION: 6.0      LAST MODIFIED: 03/11/91   BY: afs *D414*               */
/* REVISION: 6.0      LAST MODIFIED: 03/18/91   BY: MLB *D443*               */
/* REVISION: 6.0      LAST MODIFIED: 04/02/91   BY: WUG *D472*               */
/* REVISION: 6.0      LAST MODIFIED: 10/07/91   BY: alb *D887*               */
/* REVISION: 7.0      LAST MODIFIED: 11/06/91   BY: pma *F003*               */
/* REVISION: 7.0      LAST MODIFIED: 02/12/92   BY: pma *F190*               */
/* REVISION: 7.0      LAST MODIFIED: 02/26/92   BY: afs *F240*               */
/* REVISION: 7.0      LAST MODIFIED: 03/20/92   BY: dld *F297*               */
/* REVISION: 7.0      LAST MODIFIED: 04/06/92   BY: dld *F358*               */
/* REVISION: 7.0      LAST MODIFIED: 05/13/92   BY: sas *F450*               */
/* REVISION: 7.0      LAST MODIFIED: 06/08/92   BY: tjs *F504*               */
/* REVISION: 7.0      LAST MODIFIED: 07/23/92   BY: tjs *F805*               */
/* REVISION: 7.0      LAST MODIFIED: 08/19/92   BY: tjs *F859*               */
/* REVISION: 7.4      LAST MODIFIED: 09/16/93   BY: dpm *H075*               */
/* REVISION: 7.4      LAST MODIFIED: 01/28/94   BY: dpm *FL77*               */
/* REVISION: 7.4      LAST MODIFIED: 03/23/94   BY: dpm *FM97*               */
/* REVISION: 7.4      LAST MODIFIED: 04/25/94   BY: WUG *GJ58*               */
/* REVISION: 7.4      LAST MODIFIED: 07/13/94   BY: dpm *FP41*               */
/* REVISION: 7.4      LAST MODIFIED: 08/12/94   BY: dpm *FQ11*               */
/* REVISION: 7.4      LAST MODIFIED: 09/11/94   BY: rmh *GM13*               */
/* REVISION: 7.4      LAST MODIFIED: 10/04/94   BY: pxd *FR90*               */
/* REVISION: 7.4      LAST MODIFIED: 12/12/94   BY: dpm *FT84*               */
/* REVISION: 7.4      LAST MODIFIED: 01/05/95   BY: jxz *G0BG*               */
/* REVISION: 7.4      LAST MODIFIED: 02/24/95   BY: smp *F0H4*               */
/* REVISION: 8.5      LAST MODIFIED: 03/29/95   BY: dpm *J044*               */
/* REVISION: 7.4      LAST MODIFIED: 08/16/95   BY: bcm *G0V5*               */
/* REVISION: 7.4      LAST MODIFIED: 10/05/95   BY: ais *G0YK*               */
/* REVISION: 7.4      LAST MODIFIED: 11/02/95   BY: jym *F0TC*               */
/* REVISION: 8.6      LAST MODIFIED: 09/23/96   BY: flm *K003*               */
/* REVISION: 8.6      LAST MODIFIED: 01/30/97   BY: kxn *K05G*               */
/* REVISION: 8.6      LAST MODIFIED: 03/15/97   BY: *K04X* Steve Goeke       */
/* REVISION: 8.6      LAST MODIFIED: 04/14/97   BY: *H0X6* Jim Williams      */
/* REVISION: 8.6      LAST MODIFIED: 07/21/97   BY: *H1C8* Jim Williams      */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 8.6E     LAST MODIFIED: 06/25/98   BY: *L034* Markus Barone     */
/* REVISION: 9.0      LAST MODIFIED: 09/30/98   BY: *J2CZ* Reetu Kapoor      */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   BY: *M0B8* Hemanth Ebenezer  */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.0      LAST MODIFIED: 04/21/99   BY: *F0Y0* Poonam Bahl       */
/* REVISION: 9.0      LAST MODIFIED: 06/22/99   BY: *J3BX* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Robin McCarthy    */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KR* myb               */
/* REVISION: 9.1      LAST MODIFIED: 01/18/01   BY: *M0W0* Rajesh Kini       */
/* REVISION: 9.1      LAST MODIFIED: 09/25/00   BY: *N0WY* Mudit Mehta       */
/* Revision: 1.24     BY: Russ Witt             DATE: 09/21/01 ECO: *P01H*   */
/* Revision: 1.25     BY: Anitha Gopal          DATE: 10/18/01 ECO: *M1N1*   */
/* Revision: 1.26.1.1 BY: Nikita Joshi          DATE: 10/22/01 ECO: *M1LW*   */
/* Revision: 1.27     BY: Rajaneesh S.          DATE: 02/21/02 ECO: *L13N*   */
/* Revision: 1.30     BY: Patrick Rowan         DATE: 03/24/02  ECO: *P00G*  */
/* Revision: 1.31     BY: Patrick Rowan         DATE: 05/20/02  ECO: *P061*  */
/* Revision: 1.32     BY: Jeff Wootton          DATE: 05/20/02  ECO: *P03G*  */
/* Revision: 1.33     BY: Patrick Rowan         DATE: 05/24/02  ECO: *P018*  */
/* Revision: 1.35     BY: Steve Nugent          DATE: 06/05/02  ECO: *P07Y*  */
/* Revision: 1.38     BY: Dan Herman            DATE: 06/17/02  ECO: *P091*  */
/* Revision: 1.39     BY: Nishit V              DATE: 06/27/02  ECO: *N1M2*  */
/* Revision: 1.40     BY: Abbas Hirkani         DATE: 07/24/02  ECO: *P0C3*  */
/* Revision: 1.41     BY: Ed van de Gevel       DATE: 09/05/02  ECO: *P0HQ*  */
/* Revision: 1.42     BY: Mamata Samant         DATE: 09/12/02  ECO: *N1TP*  */
/* Revision: 1.43   BY: Mercy Chittilapilly   DATE: 01/15/03  ECO: *N244*  */
/* Revision: 1.45   BY: Subramanian Iyer DATE: 03/25/03  ECO: *M22J*  */
/* Revision: 1.46   BY: Narathip W.      DATE: 05/08/03  ECO: *P0RL*  */
/* $Revision: 1.46.1.1 $  BY: Santosh Rao      DATE: 06/25/03  ECO: *N2HN*  */
/*V8:ConvertMode=Maintenance                                                 */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/************************************************************************/
/*!
    {1} = "input frame bi" for use on delete or modify
    {1} = " " for add
    {2} = "update in_qty_req" to update in_qty_req
    {2} = anything else to prevent update of in_qty_req
*/
/**************************************************************/

{cxcustom.i "MFIVTR.I"}

define variable is_wo_issue as logical initial false no-undo.
define variable io_batch like cnsu_batch no-undo.
define variable using_supplier_consignment as logical no-undo.
{&MFIVTR-I-TAG9}

if execname = "soivmt.p"
then
   for each sr_wkfl
      where sr_userid = mfguser
      exclusive-lock:
      delete sr_wkfl.
   end. /* FOR EACH sr_wkfl */

/* DETERMINE IF SUPPLIER CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
         "(input 'enable_supplier_consignment',
           input 11,
           input 'ADG',
           input 'cns_ctrl',
           output using_supplier_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


if  sod_um_conv = 0 then sod_um_conv = 1.
qty_left = - {1} sod_qty_chg.

if l_qty_change
or execname <> "soivmt.p"
then do:

   /*UPDATE ALLOCATION DETAIL AND LD_QTY_ALL*/
   for each lad_det
      where lad_nbr = sod_nbr
       and lad_line = string(sod_line)
       and lad_dataset = "sod_det" exclusive-lock:
      find ld_det
         where ld_site  = lad_site
            and ld_loc  = lad_loc
            and ld_lot  = lad_lot
            and ld_ref  = lad_ref
            and ld_part = lad_part exclusive-lock no-error.
      if available ld_det
      then
         ld_qty_all = ld_qty_all - (lad_qty_all + lad_qty_pick).
      delete lad_det.
   end.

   {&MFIVTR-I-TAG1}
   /* DELETE KIT COMPONENT DETAIL ALLOCATIONS */
   {gprun.i ""soktdel1.p"" "(input recid(sod_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.


end. /* IF l_qty_change OR .. */

prev_found = no.
do for sr_wkfl
   while qty_left <> 0
   or can-find(first sr_wkfl
                  where sr_userid = mfguser
                  and trim(sr_lineid) = trim(string(sod_line))):

   trqty = qty_left.
   site = {1} sod_site.
   /* RETAINING THE OLD VALUES OF LOCATION AND LOTSER WHEN THEY ARE */
   /* EDITED SO THAT THE INVENTORY IS CORRECTLY ALLOCATED BACK      */
   /* TO THE OLD LOCATION AND LOTSER                                */

   if not l_lotedited
   then do:
      if location = "" then location = {1} sod_loc.
      if lotser = "" then lotser = {1} sod_serial.
   end. /* IF NOT L_LOTEDITED */

   /* CHECK TO SEE IF ITEM SERIAL NUMBER CONTROLLED */
   find first sr_wkfl where sr_userid = mfguser
   and   trim(sr_lineid) = trim(string(sod_line))
   exclusive-lock no-error.

   if available sr_wkfl then do:
      site = sr_site.
      location = sr_loc.
      lotser = sr_lotser.
      lotrf = sr_ref.
      trqty = - sr_qty.
      delete sr_wkfl.
   end.

   {&MFIVTR-I-TAG2}
   if site <> sod_site and sod_type <> "m" then do:
      global_part = sod_part.
      global_addr = so_cust.
      {&MFIVTR-I-TAG3}
      transtype = "ISS-SO".
      {&MFIVTR-I-TAG4}

      /*INPUT PARAMETER ORDER:                                */
      /*TR_LOT, TR_SERIAL, QUANTITY, LOTREF_FROM, LOTREF_TO   */
      /*TR_NBR, TR_SO_JOB, TR_RMKS, PROJECT, TR_EFFDATE,      */
      /*SITE_FROM, LOC_FROM, SITE_TO, LOC_TO, TEMPID          */
      /*GLCOST                                                */
      /*ASSAY, GRADE, EXPIRE                                  */

      if not available pt_mstr then
      for first pt_mstr
      where pt_part = sod_part no-lock: end.

      {&MFIVTR-I-TAG5}
      {gprun.i ""icxfer.p"" "(trlot,
                              lotser,
                              lotrf,
                              lotrf,
                              -1 * trqty * {1} sod_um_conv,
                              {1} sod_nbr,
                              {1} sod_nbr,
                              """",
                              """",
                              eff_date,
                              site,
                              location,
                              sod_site,
                              if available pt_mstr then
                                pt_loc else location,
                              no,
                              """",
                              ?,
                              """",
                              0,
                              output glcost,
                              output iss_trnbr,
                              output rct_trnbr,
                              input-output assay,
                              input-output grade,
                              input-output expire)"
      }
/*GUI*/ if global-beam-me-up then undo, leave.

      {&MFIVTR-I-TAG10}

      {&MFIVTR-I-TAG6}
   end.

   if available pl_mstr then
   for first pld_det
   where pld_prodline = pl_prod_line
   and pld_site = sod_site no-lock: end.



   assign
      trgl_recno = ?
      sct_recno = ?
      glxcst = 0
      gl_amt = 0
      dr_acct = ""
      dr_sub = ""
      dr_cc = ""
      .

   base-price = {1} sod_price / {1} sod_um_conv.
   if so_curr <> base_curr then do:
      /* CONVERT PRICE TO BASE CURRENCY */
      {gprunp.i "mcpl" "p" "mc-curr-conv"
                "(input  so_curr,
                  input  base_curr,
                  input  exch_rate,
                  input  exch_rate2,
                  input  base-price,
                  input  no,   /* DO NOT ROUND */
                  output base-price,
                  output mc-error-number)"}
   end.  /* if so_mstr.so_curr <> base_curr */

   if available pt_mstr
   then do:
      {gpsct06.i &part=sod_part
                 &site=sod_site
                 &type=""GL""}
   end. /* IF AVAILABLE pt_mstr */

   assign
      sct_recno = recid(sct_det)
      recno     = sct_recno.


if consigned_line_item and
   ((-1 * trqty) > 0            /* NORMAL SHIPMENT */
          or
   (-1 * trqty) < 0 and consigned_return_material)
then do:

   /* FIND THE CONSIGNMENT AND INTRANSIT LOCATION FROM SALES ORDER */
   {gprunmo.i
      &program = "socnsod1.p"
      &module = "ACN"
      &param = """(input so_nbr,
                   input sod_line,
                   output consign_flag,
                   output consign_loc,
                   output intrans_loc,
                   output max_aging_days,
                   output auto_replenish)"""}

   /* DETERMINE CONSIGNMENT ACCOUNTS */

   {gprunmo.i
      &program = "socnacct.p"
      &module = "ACN"
      &param = """(input sod_part,
                   input sod_site,
                   input consigned_to_location,
                   output consign_inv_acct,
                   output consign_inv_sub,
                   output consign_inv_cc,
                   output consign_intrans_acct,
                   output consign_intrans_sub,
                   output consign_intrans_cc,
                   output consign_offset_acct,
                   output consign_offset_sub,
                   output consign_offset_cc)"""}

    /* SET GLOBAL VARIABLES */

    assign
       global_part = sod_part
       global_addr = so_cust.

   /* PERFORM MATERIAL TRANSFER */
   /* ADDED TWO OUTPUT PARAMETERS FOR CONSIGNMENT*/
   {gprun.i ""icxfer.p""
             "(trlot,
               lotser,
               lotrf,
               lotrf,
               -1 * trqty * {1} sod_um_conv,
               {1} sod_nbr,
               {1} sod_nbr,
               l_rmks,
               l_project,
               eff_date,
               site,
               location,
               sod_site,
               consigned_to_location,
               no,
               l_asn_shipper,
               eff_date,
               l_invmov,
               0,
               output glcost,
               output iss_trnbr,
               output rct_trnbr,
               input-output assay,
               input-output grade,
               input-output expire)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   /* CREATE CN-SHP TRANSACTION */
   /* PASS IN THE RCT_TRNBR TO ICXFER3, TO BE USED FOR REMARKS*/
   l_trnbr = rct_trnbr.
   {gprunmo.i
      &program = "icxfer3.p"
      &module = "ACN"
      &param = """(input trlot,
                   input lotser,
                   input lotrf,
                   input lotrf,
                   input -1 * trqty * {1} sod_um_conv,
                   input {1} sod_nbr,
                   input {1} sod_nbr,
                   input {1} sod_line,
                   input l_rmks,
                   input l_project,
                   input eff_date,
                   input site,
                   input location,
                   input sod_site,
                   input consigned_to_location,
                   input no,
                   input l_asn_shipper,
                   input eff_date,
                   input l_invmov,
                   input (if consigned_to_location = intrans_loc
                          then
                              consign_intrans_acct
                                        else
                                           consign_inv_acct),
                             input (if consigned_to_location = intrans_loc
                                        then
                                           consign_intrans_sub
                                        else
                                           consign_inv_sub),
                             input (if consigned_to_location = intrans_loc
                                        then
                                           consign_intrans_cc
                                        else
                                           consign_inv_cc),
                             input consign_offset_acct,
                             input consign_offset_sub,
                             input consign_offset_cc,
                             input so_curr,
                             input base-price,
                             input sod_qty_ord - sod_qty_ship,
                             output glcost,
                             input-output l_trnbr,
                             input-output assay,
                             input-output grade,
                             input-output expire)"""}

   /* CREATE CONSIGNMENT SHIPMENT-INVENTORY X-REF */

   /* PARAMETER io_first_time get passed in as yes initially       */
   /* to & socncix.p. When io_first_time is yes, then socncix.p    */
   /* will create a new cross ref rec.  Once io_first_time is      */
   /* NO, socncix.p will try to reuse the same cross refernce rec  */
   /* if all other key information is the same.                    */

   {gprunmo.i
      &program = "socncix.p"
      &module = "ACN"
      &param = """(input sod_nbr,
                   input sod_line,
                   input sod_site,
                   input so_ship_date,
                   input (trqty * -1) * sod_um_conv,
                   input sod_um,
                   input l_asn_shipper,
                   input l_trnbr,
                   input consigned_to_location,
                   input lotser,
                   input lotrf,
                   input l_auth,
                   input l_cust_job,
                   input l_cust_seq,
                   input l_cust_ref,
                   input l_dock,
                   input l_line_feed,
                   input l_modelyr,
                   input true,
                   input-output io_first_time)"""}

   /* RETRIEVE THE ISS-TR tr_hist TO LATER SAVE THE REC-ID */
   /* AND TO REDUCE THE REQUIRED QTY IN INVENTORY MASTER.  */
   for first tr_hist
       where  tr_trnbr = iss_trnbr
       no-lock:
       end.

end.  /* if consigned_line_item */
else do:

   {&MFIVTR-I-TAG7}

   {ictrans.i
      &addrid=so_cust
      &bdnstd=0
      &cracct="
         if available pt_mstr then
            if available pld_det then pld_inv_acct
            else pl_inv_acct
         else """""
      &crsub="
         if available pt_mstr then
            if available pld_det then pld_inv_sub
            else pl_inv_sub
         else """""
      &crcc="
         if available pt_mstr then
            if available pld_det then pld_inv_cc
            else pl_inv_cc
         else """""
      &crproj="{1} sod_project"
      &curr=so_curr
      &dracct=dr_acct
      &drsub=dr_sub
      &drcc=dr_cc
      &drproj="{1} sod_project"
      &effdate=eff_date
      &exrate=exch_rate
      &exrate2=exch_rate2
      &exratetype=exch_ratetype
      &exruseq=exch_exru_seq
      &glamt=gl_amt
      &lbrstd=0
      &line="{1} sod_line"
      &location="(if site <> sod_site and available pt_mstr
        then pt_loc else location)"
      &lotnumber=trlot
      &lotserial=lotser
      &lotref=lotrf
      &mtlstd="if sod_type = 'M' and not available pt_mstr
               then sod_std_cost else 0"
      &ordernbr="{1} sod_nbr"
      &ovhstd=0
      &part=sod_part
      &perfdate="{1} sod_per_date"
      &price=base-price
      &promisedate="{1} sod_promise_date"
      &quantityreq=
         "if new sod_det then
            ({1} sod_bo_chg + {1} sod_qty_chg) * {1} sod_um_conv
         else
            ({1} sod_qty_ord - {1} sod_qty_ship) * {1} sod_um_conv"
      &quantityshort="{1} sod_bo_chg * {1} sod_um_conv"
      &quantity="trqty * {1} sod_um_conv"
      &revision=""""
      &rmks=""""
      &shiptype="{1} sod_type"
      &site=sod_site
      &slspsn1="{1} sod_slspsn[1]"
      &slspsn2="{1} sod_slspsn[2]"
      &slspsn3="tr_slspsn[3] = {1} sod_slspsn[3]"
      &slspsn4="tr_slspsn[4] = {1} sod_slspsn[4]"
      &sojob="if sod_fsm_type begins """RMA""" then
                 {1} sod_contr_id
              else
                 {1} sod_nbr"
      &substd=0
      &transtype=""ISS-SO""
      &msg=0
      &ref_site=tr_site
      &tempid=1
      &trordrev="tr_ord_rev = so_rev"
      &shipnbr = shipnbr
   }
   {&MFIVTR-I-TAG11}

   if execname = "sosois.p"
   or execname = "soivmt.p"
   or execname = "fsrmash.p"
   then do:
      for first clc_ctrl
         fields(clc_lotlevel)
         no-lock:
      end. /* FOR FIRST clc_ctrl */

      if available clc_ctrl
      then do :

         if clc_lotlevel = 1
         then do :
            for each lotw_wkfl
               where lotw_mfguser = mfguser
                 and lotw_lotser  = lotser
                 and lotw_part    = sod_part
               exclusive-lock :
               delete lotw_wkfl.
            end. /* FOR EACH lotw_wkfl */
         end. /* IF clc_lotlevel */

         if clc_lotlevel = 2
         then do :
            for each lotw_wkfl
               where lotw_mfguser = mfguser
                 and lotw_lotser  = lotser
               exclusive-lock:
               delete lotw_wkfl.
            end. /* FOR EACH lotw_wkfl */
         end. /* if clc_lotlevel */

      end. /* IF AVAILABLE clc_ctrl */
   end. /* IF execname = ... */


   {&MFIVTR-I-TAG8}

   {gprun.i ""socost01.p""
                  "(trqty * {1} sod_um_conv,
                    lotser,
                    prev_found,
                    sod_entity,
                    location,
                    recid(tr_hist) )"}
/*GUI*/ if global-beam-me-up then undo, leave.


   assign
      prev_found = yes
      recno      = sct_recno.

   if available pt_mstr and sod_prodline <> pt_prod_line then
   if sod_fsm_type = "" and sod_rma_type = "" then
   do for soddet:
      find soddet where soddet.sod_nbr = sod_det.sod_nbr and
                        soddet.sod_line = sod_det.sod_line
                        exclusive-lock no-error.
      if available soddet then
         soddet.sod_prodline = pt_prod_line.
   end.

   assign tr_prod_line = sod_prodline
          tr_fsm_type  = sod_fsm_type
          tr_ship_date = so_ship_date.

   if site <> sod_site then do:
      tr_assay = assay.
      tr_grade = grade.
      tr_expire = expire.
   end.

   {gprun.i ""socost02.p"" "(trqty * {1} sod_um_conv, sod_entity,
            recid(trgl_det), recid(tr_hist) )"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* CREATE CONSIGNMENT USAGE RECORDS IF CONSIGNMENT ENABLED*/
   /* AND CONSIGNMENT INVENTORY EXISTS.                      */
   if using_supplier_consignment then do:

      /* CHANGED THE SECOND INPUT PARAMETER */
      /* FROM so_site TO sod_site           */
      {gprunmo.i
         &program = ""pocnsix4.p""
         &module  = "ACN"
         &param   =  """(input sod_part,
                         input sod_site,
                         input right-trim(substring(lotser,1,18)),
                         input lotrf,
                         output consign_flag)"""}

      /*IF CONSIGNED INVENTORY EXISTS, DETERMINE WHETHER TO */
      /*USE IT PRIOR TO UNCONSIGNED INVENTORY.              */
      if consign_flag then do:
         {gprunmo.i
            &program = ""ictrancn.p""
            &module  = "ACN"
            &param   =  """(input sod_nbr,
                            input '',
                            input 0,
                            input tr_so_job,
                            input - trqty,
                            input lotser,
                            input sod_part,
                            input sod_site,
                            input location,
                            input lotrf,
                            input eff_date,
                            input tr_trnbr,
                            input is_wo_issue,
                            input-output io_batch)"""}
      end. /*If consign_flag*/
   end. /*IF USING_SUPPLIER_CONSIGNMENT*/

end. /* ELSE DO */

  tr_recno = recid(tr_hist).

   /* DO NOT UPDATE IN_QTY_REQ FOR RMA RECEIPT LINES */
   if {1} sod_type = ""
   and not {1} sod_sched
   and ({1} sod_fsm_type <> "RMA-RCT")
   then do:
      if not site_change then do:
         find in_mstr where in_part = {1} sod_part and in_site = {1}
         sod_site exclusive-lock no-error.

         if available in_mstr then do:
            if {2} = "update in_qty_req"
            then do:
               if pend_inv then do:
                  assign in_qty_req = in_qty_req + tr_qty_loc.
               end.
               else do: /* not pend_inv */
                  /* Update Qty Required on in_mstr.  Note: tr_qty_loc is */
                  /* negative on shipments, positive on cr order returns. */
                  /* sod_qty_ship hasn't been updated w/new shipment yet. */
                  if {1} sod_qty_ord >= 0 then      /* Order Shipment */
                     in_qty_req = in_qty_req -
                     MAX(({1} sod_qty_ord * {1} sod_um_conv -
                         {1} sod_qty_ship * {1} sod_um_conv),0) +
                     MAX({1} sod_qty_ord * {1} sod_um_conv -
                      ({1} sod_qty_ship * {1} sod_um_conv - tr_qty_loc),0).
                  if {1} sod_qty_ord < 0 then       /* Cr Order Return */
                     in_qty_req = in_qty_req -
                     MIN(({1} sod_qty_ord * {1} sod_um_conv -
                          {1} sod_qty_ship * {1} sod_um_conv),0) +
                     MIN({1} sod_qty_ord * {1} sod_um_conv  -
                      ({1} sod_qty_ship * {1} sod_um_conv - tr_qty_loc),0).
                  sod_qty_ship = sod_qty_ship - tr_qty_loc / sod_um_conv.
               end.   /* not pend invoice */
            end. /* {2} = update in_qty_req */
         end.   /* avail in_mstr */
      end.   /* not site_change */
   end.   /* sod_type = "" */
   qty_left = qty_left - trqty.

end.
